/**
 * createElement函数用于将jsx转化为VDOM对象
 * 1. 文本节点也将会是一个VDOM对象
 * 2. 条件判断为false的对象不会转化为VDOM
 * 3. props中可通过children属性访问子元素的VDOM
 */
export default function createElement (type, props, ...children) {

  const childElements = [].concat(...children).reduce((result, child) => {
    if(child !== false && child !== null && child !== true) {
      if (child instanceof Object) {
        result.push(child)
      } else {
        child = createElement('text', { textContent: child })
        result.push(child)
      }
    }
    return result
  }, [])

  return {
    type,
    // props访问子元素VDOM
    props: Object.assign({ children: childElements }, props),
    children: childElements
  }
}